{% import "macros.html" as macros %}
{% if 'SIDEBAR_QUESTION_HEADER'|show_block_to(request.user) %}
<div class="box">
    {{ settings.SIDEBAR_QUESTION_HEADER }}
</div>
{% endif %}
<div class="box vote-buttons">
  <h2 style="margin-bottom: 0em">{{ settings.WORDS_QUESTION_TOOLS|escape }}</h2>
    {% if favorited %}
        <a class="button followed" 
            alt="{% trans %}click to unfollow {% endtrans %}">
            <div style="text-align: left; color: #3c6eb4;">{% trans %}Following{% endtrans %}</div>
            <button class='unfollow normal-btn'>{% trans %}Unfollow{% endtrans %}</button>
        </a>
    {% else %}
        <a class="button followed"
            alt="{% trans %}click to follow {% endtrans %}"
            id="follow-btn">
            {%trans %}Follow{%endtrans%}
        </a>
    {% endif %}
    <div class="clearfix"></div>
    <div id="favorite-number" class="favorite-number{% if favorited %} my-favorite-number{% endif %}" style="margin-top: 0.5em;margin-bottom: 0.3em;float: left;">
        {% set follower_count = thread.favourite_count %}
        {% if follower_count > 0 %}
            {% trans count=follower_count %}{{count}} follower{% pluralize %}{{count}} followers{% endtrans %}
        {% endif %}
    </div>
    <div class="notify-sidebar">
        {% if settings.RSS_ENABLED %}
        <p class="rss">
            <a
                href="{{ base_url }}/feeds/question/{{ question.id }}"
                title="{% trans %}subscribe to the rss feed{% endtrans %}"
                style="text-decoration: none; color: #3c6eb4"
                >{% trans %}subscribe to rss feed{% endtrans %}</a>
        </p>
        {% endif %}
    </div> 
</div>
<div class="clearfix"></div>
{% if settings.GROUPS_ENABLED %}
<div class="box sharing-widget">
    {% if thread.is_private() %}
        <h2>{% trans %}Invite{% endtrans %}</h2>
        <p style="margin: 16px 0">{{ settings.WORDS_INVITE_OTHERS_TO_HELP_ANSWER_THIS_QUESTION|escape }}</p>
        <form action="{% url share_question_with_user %}" method="post">{% csrf_token %}
            <input id="share_user_name" type="text" class="groups-input" name="recipient_name" />
            <input type="hidden" name="thread_id" value="{{ thread.id }}"/>
            <input type="submit" class="add-groups" value="{% trans %}add{% endtrans %}"/>
        </form>
        <p class="share-input-col">{% trans %}- or -{% endtrans %}</p>
        <form action="{% url share_question_with_group %}" method="post">{% csrf_token %}
            <input id="share_group_name" type="text" class="groups-input" name="recipient_name" />
            <input type="hidden" name="thread_id" value="{{ thread.id }}"/>
            <input type="submit" class="add-groups" value="{% trans %}add{% endtrans %}"/>
        </form>
        <p class="share-input-col">{% trans %}- or -{% endtrans %}</p>
        <form action="{% url share_question_with_group %}" method="post">{% csrf_token %}
            <input
                type="hidden"
                name="recipient_name"
                value="{{ settings.GLOBAL_GROUP_NAME }}"
            />
            <input type="hidden" name="thread_id" value="{{ thread.id }}"/>
            <p class="share-input-col">
            <input 
                type="submit"
                class="add-groups add-everyone-group"
                value="{% trans %}share with everyone{% endtrans %}"
            />
            </p>
        </form>
        {% set shared_users_count = sharing_info['users'].count() %}
        {% set shared_groups_count = sharing_info['groups'].count() %}
        {% if shared_users_count or shared_groups_count %}
            <p 
                style="margin:16px 0 4px 0"
            >{{ settings.WORDS_THIS_QUESTION_IS_CURRENTLY_SHARED_ONLY_WITH|escape }}</p>
        {% endif %}
        <h3>{% trans %}Individual users{% endtrans %}</h3>
            {% set comma = joiner(',') %}
            {{ comma() }}
        <p>
        <a href="{{ request.user.get_profile_url() }}">
            {% trans %}You{% endtrans -%}
        </a>{%- if shared_users_count -%}
                {%- for user in sharing_info['users'] %}{{ comma() }}
                    {{ user.get_profile_link() }}
                {%- endfor -%}
            {% endif -%}
            {%- if sharing_info['more_users_count'] > 0 %}
                {% trans %}and{% endtrans %}
                <a 
                    class="see-related-users"
                    data-url="{% url get_thread_shared_users %}"
                    data-thread-id="{{ thread.id }}"
                >{% trans 
                        more_count=sharing_info['more_users_count'] 
                    %}{{ more_count }} more{% endtrans %}
                </a>
            {% endif %}
        </p>
        {% if shared_groups_count %}
            <h3>{% trans %}Groups{% endtrans %}</h3>
            <p>
                {% set comma = joiner(',') %}
                {%- for group in sharing_info['groups'] -%}{{ comma() }}
                    {{ macros.user_group_link(group) }}
                {%- endfor -%}
                {% if sharing_info['more_groups_count'] > 0 %}
                    {% trans %}and{% endtrans %}
                    <a 
                        class="see-related-groups"
                        data-url="{% url get_thread_shared_groups %}"
                        data-thread-id="{{ thread.id }}"
                    >{% trans more_count=sharing_info['more_groups_count'] %}{{ more_count }} more{% endtrans %}
                    </a>
                {% endif %}
            </p>
        {% endif %}
    {% else %}
        <h2>{% trans %}Public thread{% endtrans %}</h2>
        <p>{% trans site_name=settings.APP_SHORT_NAME %}This thread is public, all members of {{ site_name }} can read this page.{% endtrans %}</p>
    {% endif %}
</div>
{% endif %}
{% if settings.SIDEBAR_QUESTION_SHOW_META %}
<div class="box statsWidget">
    <div class="clearfix"></div>
    <h2>{% trans %}Stats{% endtrans %}</h2>
    <table style="width: 100%">
        <tr>
            <td>
                {% trans %}Asked{% endtrans %}: 
            </td>
            <td>
                <strong>{{ macros.timeago(question.added_at) }}</strong>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <hr style="margin: 0.3em 0 0.3em 0;border-top: 0px solid #eeeeee;border-bottom: 1px solid #eeeeee;">
            </td>
        </tr>
        <tr>
            <td>
                {% trans %}Seen{% endtrans %}: 
            </td>
            <td>
                <strong>{{ thread.view_count|intcomma }} {% trans %}times{% endtrans %}</strong>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <hr style="margin: 0.3em 0 0.3em 0;border-top: 0px solid #eeeeee;border-bottom: 1px solid #eeeeee;">
            </td>
        </tr>
        <tr>
            <td>
                {% trans %}Last updated{% endtrans %}:&nbsp;
            </td>
            <td>
                <strong title="{{ thread.last_activity_at }}">{{thread.last_activity_at|diff_date}}</strong>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <hr style="margin: 0.3em 0 0.3em 0;border-top: 0px solid #eeeeee;border-bottom: 1px solid #eeeeee;">
            </td>
        </tr>
    </table>
</div>
{% endif %}
{% if similar_threads.data() and settings.SIDEBAR_QUESTION_SHOW_RELATED %}
    {#% cache 1800 "related_questions" related_questions question.id language_code %#}
    <div class="box" style="background-color: #F4F4F4;padding: 1em;margin-top: 1em;">
      <h2>{{ settings.WORDS_RELATED_QUESTIONS|escape }}</h2>
        <div class="questions-related">
            {% for thread_dict in similar_threads.data() %}
            <p>
                <a href="{{ thread_dict.url }}" style="text-decoration: none; color: #3c6eb4">{{ thread_dict.title|escape }}</a>
            </p>
            {% endfor %}
        </div>
    </div>
    {#% endcache %#}
{% endif %}

{% if 'SIDEBAR_QUESTION_FOOTER'|show_block_to(request.user) %}
    <div class="box" style="background-color: #F4F4F4;padding: 1em;margin-top: 1em;">
        {{ settings.SIDEBAR_QUESTION_FOOTER }}
    </div>
{% endif %}
